<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>IO::Compress::Zip - Write zip files/buffers - Perldoc Browser</title>
    <link rel="search" href="https://perldoc.perl.org/opensearch.xml" type="application/opensearchdescription+xml" title="Perldoc Browser">
    <link rel="canonical" href="https://perldoc.perl.org/IO::Compress::Zip">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css" integrity="sha384-JcKb8q3iqJ61gNV9KGb8thSsNjpSL0n8PARn9HuZOnIxN0hoP+VmmDGMN5t9UJ0Z" crossorigin="anonymous">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/highlight.js/10.5.0/styles/stackoverflow-light.min.css" integrity="sha512-cG1IdFxqipi3gqLmksLtuk13C+hBa57a6zpWxMeoY3Q9O6ooFxq50DayCdm0QrDgZjMUn23z/0PMZlgft7Yp5Q==" crossorigin="anonymous" />
    <style>
      body {
        background: #f4f4f5;
        color: #020202;
      }
      .navbar-dark {
        background-image: -webkit-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: -o-linear-gradient(top, #005f85 0, #002e49 100%);
        background-image: linear-gradient(to bottom, #005f85 0, #002e49 100%);
        filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#ff005f85', endColorstr='#ff002e49', GradientType=0);
        background-repeat: repeat-x;
      }
      .navbar-dark .navbar-nav .nav-link,
      .navbar-dark .navbar-nav .nav-link:focus { color: #fff }
      .navbar-dark .navbar-nav .nav-link:hover { color: #ffef68 }
      #wrapperlicious {
        margin: 0 auto;
        font: 0.9em 'Helvetica Neue', Helvetica, sans-serif;
        font-weight: normal;
        line-height: 1.5em;
        margin: 0;
        padding: 0;
      }
      #wrapperlicious h1 { font-size: 1.5em }
      #wrapperlicious h2 { font-size: 1.3em }
      #wrapperlicious h3 { font-size: 1.1em }
      #wrapperlicious h4 { font-size: 0.9em }
      #wrapperlicious h1, #wrapperlicious h2, #wrapperlicious h3,
      #wrapperlicious h4, #wrapperlicious dt {
        color: #020202;
        margin-top: 1em;
        margin-bottom: 1em;
        position: relative;
        font-weight: bold;
      }
      #wrapperlicious a { color: inherit; text-decoration: underline }
      #wrapperlicious #toc { text-decoration: none }
      #wrapperlicious a:hover { color: #2a2a2a }
      #wrapperlicious a img { border: 0 }
      #wrapperlicious :not(pre) > code {
        color: inherit;
        background-color: rgba(0, 0, 0, 0.04);
        border-radius: 3px;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        padding: 0.3em;
      }
      #wrapperlicious dd {
        margin: 0;
        margin-left: 2em;
      }
      #wrapperlicious dt {
        color: #2a2a2a;
        font-weight: bold;
        margin-left: 0.9em;
      }
      #wrapperlicious p {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious li > p {
        margin-bottom: 0;
        margin-top: 0;
      }
      #wrapperlicious pre {
        border: 1px solid #c1c1c1;
        border-radius: 3px;
        font: 100% Consolas, Menlo, Monaco, monospace;
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious pre > code {
        display: block;
        background-color: #f6f6f6;
        font: 0.9em Consolas, Menlo, Monaco, monospace;
        line-height: 1.5em;
        text-align: left;
        white-space: pre;
        padding: 1em;
      }
      #wrapperlicious dl, #wrapperlicious ol, #wrapperlicious ul {
        margin-bottom: 1em;
        margin-top: 1em;
      }
      #wrapperlicious ul {
        list-style-type: square;
      }
      #wrapperlicious ul ul {
        margin-bottom: 0px;
        margin-top: 0px;
      }
      #footer {
        font-size: 0.8em;
        padding-top: 0.5em;
        text-align: center;
      }
      #more {
        display: inline;
        font-size: 0.8em;
      }
      #perldocdiv {
        background-color: #fff;
        border: 1px solid #c1c1c1;
        border-bottom-left-radius: 5px;
        border-bottom-right-radius: 5px;
        margin-left: auto;
        margin-right: auto;
        padding: 3em;
        padding-top: 1em;
        max-width: 960px;
      }
      #moduleversion { float: right }
      #wrapperlicious .leading-notice {
        font-style: italic;
        padding-left: 1em;
        margin-top: 1em;
        margin-bottom: 1em;
      }
      #wrapperlicious .permalink {
        display: none;
        left: -0.75em;
        position: absolute;
        padding-right: 0.25em;
        text-decoration: none;
      }
      #wrapperlicious h1:hover .permalink, #wrapperlicious h2:hover .permalink,
      #wrapperlicious h3:hover .permalink, #wrapperlicious h4:hover .permalink,
      #wrapperlicious dt:hover .permalink {
        display: block;
      }
    </style>
    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=G-KVNWBNT5FB"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());

      gtag('config', 'G-KVNWBNT5FB');
      gtag('config', 'UA-50555-3');
    </script>
  </head>
  <body>
    <nav class="navbar navbar-expand-md navbar-dark bg-dark justify-content-between">
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <a class="navbar-brand" href="https://perldoc.perl.org/">Perldoc Browser</a>
  <div class="collapse navbar-collapse" id="navbarNav">
    <ul class="navbar-nav mr-auto">
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Compress::Zip.html#" id="dropdownlink-stable" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">5.35.0</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-stable">
          <a class="dropdown-item" href="https://perldoc.perl.org/IO::Compress::Zip">Latest</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.2/IO::Compress::Zip">5.38.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.1/IO::Compress::Zip">5.38.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0/IO::Compress::Zip">5.38.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.3/IO::Compress::Zip">5.36.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.2/IO::Compress::Zip">5.36.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.1/IO::Compress::Zip">5.36.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.36.0/IO::Compress::Zip">5.36.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.3/IO::Compress::Zip">5.34.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.2/IO::Compress::Zip">5.34.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.1/IO::Compress::Zip">5.34.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.34.0/IO::Compress::Zip">5.34.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.1/IO::Compress::Zip">5.32.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.32.0/IO::Compress::Zip">5.32.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.3/IO::Compress::Zip">5.30.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.2/IO::Compress::Zip">5.30.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.1/IO::Compress::Zip">5.30.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.30.0/IO::Compress::Zip">5.30.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.3/IO::Compress::Zip">5.28.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.2/IO::Compress::Zip">5.28.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.1/IO::Compress::Zip">5.28.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.28.0/IO::Compress::Zip">5.28.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.3/IO::Compress::Zip">5.26.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.2/IO::Compress::Zip">5.26.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.1/IO::Compress::Zip">5.26.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.26.0/IO::Compress::Zip">5.26.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.4/IO::Compress::Zip">5.24.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.3/IO::Compress::Zip">5.24.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.2/IO::Compress::Zip">5.24.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.1/IO::Compress::Zip">5.24.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.24.0/IO::Compress::Zip">5.24.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.4/IO::Compress::Zip">5.22.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.3/IO::Compress::Zip">5.22.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.2/IO::Compress::Zip">5.22.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.1/IO::Compress::Zip">5.22.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.22.0/IO::Compress::Zip">5.22.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.3/IO::Compress::Zip">5.20.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.2/IO::Compress::Zip">5.20.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.1/IO::Compress::Zip">5.20.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.20.0/IO::Compress::Zip">5.20.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.4/IO::Compress::Zip">5.18.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.3/IO::Compress::Zip">5.18.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.2/IO::Compress::Zip">5.18.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.1/IO::Compress::Zip">5.18.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.18.0/IO::Compress::Zip">5.18.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.3/IO::Compress::Zip">5.16.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.2/IO::Compress::Zip">5.16.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.1/IO::Compress::Zip">5.16.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.16.0/IO::Compress::Zip">5.16.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.4/IO::Compress::Zip">5.14.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.3/IO::Compress::Zip">5.14.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.2/IO::Compress::Zip">5.14.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.1/IO::Compress::Zip">5.14.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.14.0/IO::Compress::Zip">5.14.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.5/IO::Compress::Zip">5.12.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.4/IO::Compress::Zip">5.12.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.3/IO::Compress::Zip">5.12.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.2/IO::Compress::Zip">5.12.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.1/IO::Compress::Zip">5.12.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.12.0/IO::Compress::Zip">5.12.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.1/IO::Compress::Zip">5.10.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.10.0/IO::Compress::Zip">5.10.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.9/IO::Compress::Zip">5.8.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.8/IO::Compress::Zip">5.8.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.7/IO::Compress::Zip">5.8.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.6/IO::Compress::Zip">5.8.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.5/IO::Compress::Zip">5.8.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.4/IO::Compress::Zip">5.8.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.3/IO::Compress::Zip">5.8.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.2/IO::Compress::Zip">5.8.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.1/IO::Compress::Zip">5.8.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.8.0/IO::Compress::Zip">5.8.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.2/IO::Compress::Zip">5.6.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.1/IO::Compress::Zip">5.6.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.6.0/IO::Compress::Zip">5.6.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_04/IO::Compress::Zip">5.005_04</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_03/IO::Compress::Zip">5.005_03</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_02/IO::Compress::Zip">5.005_02</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005_01/IO::Compress::Zip">5.005_01</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.005/IO::Compress::Zip">5.005</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Compress::Zip.html#" id="dropdownlink-dev" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Dev</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-dev">
          <a class="dropdown-item" href="https://perldoc.perl.org/blead/IO::Compress::Zip">blead</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.6/IO::Compress::Zip">5.39.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.5/IO::Compress::Zip">5.39.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.4/IO::Compress::Zip">5.39.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.3/IO::Compress::Zip">5.39.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.2/IO::Compress::Zip">5.39.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.39.1/IO::Compress::Zip">5.39.1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC2/IO::Compress::Zip">5.38.0-RC2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.38.0-RC1/IO::Compress::Zip">5.38.0-RC1</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.11/IO::Compress::Zip">5.37.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.10/IO::Compress::Zip">5.37.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.9/IO::Compress::Zip">5.37.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.8/IO::Compress::Zip">5.37.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.7/IO::Compress::Zip">5.37.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.6/IO::Compress::Zip">5.37.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.5/IO::Compress::Zip">5.37.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.4/IO::Compress::Zip">5.37.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.3/IO::Compress::Zip">5.37.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.2/IO::Compress::Zip">5.37.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.1/IO::Compress::Zip">5.37.1</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.37.0/IO::Compress::Zip">5.37.0</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.11/IO::Compress::Zip">5.35.11</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.10/IO::Compress::Zip">5.35.10</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.9/IO::Compress::Zip">5.35.9</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.8/IO::Compress::Zip">5.35.8</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.7/IO::Compress::Zip">5.35.7</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.6/IO::Compress::Zip">5.35.6</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.5/IO::Compress::Zip">5.35.5</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.4/IO::Compress::Zip">5.35.4</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.3/IO::Compress::Zip">5.35.3</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.2/IO::Compress::Zip">5.35.2</a>
          <a class="dropdown-item" href="https://perldoc.perl.org/5.35.1/IO::Compress::Zip">5.35.1</a>
          <a class="dropdown-item active" href="./IO::Compress::Zip.html">5.35.0</a>
        </div>
      </li>
      <li class="nav-item dropdown text-nowrap">
        <a class="nav-link dropdown-toggle" href="./IO::Compress::Zip.html#" id="dropdownlink-nav" role="button" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">Documentation</a>
        <div class="dropdown-menu" aria-labelledby="dropdownlink-nav">
          <a class="dropdown-item" href="perl.html">Perl</a>
          <a class="dropdown-item" href="perlintro.html">Intro</a>
          <a class="dropdown-item" href="perl.html#Tutorials">Tutorials</a>
          <a class="dropdown-item" href="perlfaq.html">FAQs</a>
          <a class="dropdown-item" href="perl.html#Reference-Manual">Reference</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlop.html">Operators</a>
          <a class="dropdown-item" href="functions.html">Functions</a>
          <a class="dropdown-item" href="variables.html">Variables</a>
          <a class="dropdown-item" href="modules.html">Modules</a>
          <a class="dropdown-item" href="perlutil.html">Utilities</a>
          <div class="dropdown-divider"></div>
          <a class="dropdown-item" href="perlcommunity.html">Community</a>
          <a class="dropdown-item" href="perlhist.html">History</a>
        </div>
      </li>
    </ul>
    <ul class="navbar-nav">
      <script>
        function set_expand (expand) {
          var perldocdiv = document.getElementById('perldocdiv');
          var width = window.getComputedStyle(perldocdiv).getPropertyValue('max-width');
          var expanded = (width == '' || width == 'none') ? true : false;
          if (expand === null) {
            expand = !expanded;
          }
          if ((expand && !expanded) || (!expand && expanded)) {
            perldocdiv.style.setProperty('max-width', expand ? 'none' : '960px');
            var button_classlist = document.getElementById('content-expand-button').classList;
            if (expand) {
              button_classlist.add('btn-light');
              button_classlist.remove('btn-outline-light');
            } else {
              button_classlist.add('btn-outline-light');
              button_classlist.remove('btn-light');
            }
          }
          return expand;
        }
        function toggle_expand () {
          var expand = set_expand(null);
          document.cookie = 'perldoc_expand=' + (expand ? 1 : 0) + '; path=/; expires=Tue, 19 Jan 2038 03:14:07 UTC';
        }
        function read_expand () {
          return document.cookie.split(';').some(function (item) { return item.indexOf('perldoc_expand=1') >= 0 });
        }
        if (document.readyState === 'loading') {
          document.addEventListener('DOMContentLoaded', function () {
            if (read_expand()) {
              set_expand(true);
            }
          });
        } else if (read_expand()) {
          set_expand(true);
        }
      </script>
      <button id="content-expand-button" type="button" class="btn btn-outline-light d-none d-lg-inline-block mr-2" onclick="toggle_expand()">Expand</button>
    <ul>
    <form class="form-inline" method="get" action="https://perldoc.perl.org/5.35.0/search">
      <input class="form-control mr-3" type="search" name="q" placeholder="Search" aria-label="Search">
    </form>
  </div>
</nav>

    <div id="wrapperlicious" class="container-fluid">
      <div id="perldocdiv">
        <div id="links">
          <a href="./IO::Compress::Zip.html">IO::Compress::Zip</a>
          <div id="more">
            (<a href="./IO::Compress::Zip.txt">source</a>,
            <a href="https://metacpan.org/pod/IO::Compress::Zip">CPAN</a>)
          </div>
            <div id="moduleversion">version 2.102</div>
        </div>
        <div class="leading-notice">
          You are viewing the version of this documentation from Perl 5.35.0.
            This is a development version of Perl.
        </div>
        <h1><a id="toc">CONTENTS</a></h1>
                  <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#NAME">NAME</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#SYNOPSIS">SYNOPSIS</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#DESCRIPTION">DESCRIPTION</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Functional-Interface">Functional Interface</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#zip-$input_filename_or_reference-=%3E-$output_filename_or_reference-%5B,-OPTS%5D">zip $input_filename_or_reference =&gt; $output_filename_or_reference [, OPTS]</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#The-$input_filename_or_reference-parameter">The $input_filename_or_reference parameter</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#The-$output_filename_or_reference-parameter">The $output_filename_or_reference parameter</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Notes">Notes</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Optional-Parameters">Optional Parameters</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Examples">Examples</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Streaming">Streaming</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Compressing-a-file-from-the-filesystem">Compressing a file from the filesystem</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Reading-from-a-Filehandle-and-writing-to-an-in-memory-buffer">Reading from a Filehandle and writing to an in-memory buffer</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Compressing-multiple-files">Compressing multiple files</a>
              </li>
          </ul>

              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#OO-Interface">OO Interface</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Constructor">Constructor</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Constructor-Options">Constructor Options</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#File-Naming-Options">File Naming Options</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Overall-Zip-Archive-Structure">Overall Zip Archive Structure</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Deflate-Compression-Options">Deflate Compression Options</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Bzip2-Compression-Options">Bzip2 Compression Options</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Lzma-and-Xz-Compression-Options">Lzma and Xz Compression Options</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Other-Options">Other Options</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Examples1">Examples</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Methods">Methods</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#print">print</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#printf">printf</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#syswrite">syswrite</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#write">write</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#flush">flush</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#tell">tell</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#eof">eof</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#seek">seek</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#binmode">binmode</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#opened">opened</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#autoflush">autoflush</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#input_line_number">input_line_number</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#fileno">fileno</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#close">close</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#newStream(%5BOPTS%5D)">newStream([OPTS])</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#deflateParams">deflateParams</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Importing">Importing</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#EXAMPLES">EXAMPLES</a>
                            <ul>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Apache::GZip-Revisited">Apache::GZip Revisited</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#Working-with-Net::FTP">Working with Net::FTP</a>
              </li>
          </ul>

              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#SUPPORT">SUPPORT</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#SEE-ALSO">SEE ALSO</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#AUTHOR">AUTHOR</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#MODIFICATION-HISTORY">MODIFICATION HISTORY</a>
              </li>
              <li>
                <a class="text-decoration-none" href="./IO::Compress::Zip.html#COPYRIGHT-AND-LICENSE">COPYRIGHT AND LICENSE</a>
              </li>
          </ul>

      <h1 id="NAME"><a class="permalink" href="./IO::Compress::Zip.html#NAME">#</a>NAME</h1>

<p>IO::Compress::Zip - Write zip files/buffers</p>

<h1 id="SYNOPSIS"><a class="permalink" href="./IO::Compress::Zip.html#SYNOPSIS">#</a>SYNOPSIS</h1>

<pre><code>use IO::Compress::Zip qw(zip $ZipError) ;

my $status = zip $input =&gt; $output [,OPTS]
    or die &quot;zip failed: $ZipError\n&quot;;

my $z = IO::Compress::Zip-&gt;new( $output [,OPTS] )
    or die &quot;zip failed: $ZipError\n&quot;;

$z-&gt;print($string);
$z-&gt;printf($format, $string);
$z-&gt;write($string);
$z-&gt;syswrite($string [, $length, $offset]);
$z-&gt;flush();
$z-&gt;tell();
$z-&gt;eof();
$z-&gt;seek($position, $whence);
$z-&gt;binmode();
$z-&gt;fileno();
$z-&gt;opened();
$z-&gt;autoflush();
$z-&gt;input_line_number();
$z-&gt;newStream( [OPTS] );

$z-&gt;deflateParams();

$z-&gt;close() ;

$ZipError ;

# IO::File mode

print $z $string;
printf $z $format, $string;
tell $z
eof $z
seek $z, $position, $whence
binmode $z
fileno $z
close $z ;</code></pre>

<h1 id="DESCRIPTION"><a class="permalink" href="./IO::Compress::Zip.html#DESCRIPTION">#</a>DESCRIPTION</h1>

<p>This module provides a Perl interface that allows writing zip compressed data to files or buffer.</p>

<p>The primary purpose of this module is to provide streaming write access to zip files and buffers.</p>

<p>At present the following compression methods are supported by IO::Compress::Zip</p>

<dl>

<dt id="Store-(0)"><a class="permalink" href="./IO::Compress::Zip.html#Store-(0)">#</a><a id="Store"></a><a id="Store-0"></a>Store (0)</dt>
<dd>

</dd>
<dt id="Deflate-(8)"><a class="permalink" href="./IO::Compress::Zip.html#Deflate-(8)">#</a><a id="Deflate"></a><a id="Deflate-8"></a>Deflate (8)</dt>
<dd>

</dd>
<dt id="Bzip2-(12)"><a class="permalink" href="./IO::Compress::Zip.html#Bzip2-(12)">#</a><a id="Bzip2"></a><a id="Bzip2-12"></a>Bzip2 (12)</dt>
<dd>

<p>To write Bzip2 content, the module <code>IO::Uncompress::Bunzip2</code> must be installed.</p>

</dd>
<dt id="Lzma-(14)"><a class="permalink" href="./IO::Compress::Zip.html#Lzma-(14)">#</a><a id="Lzma"></a><a id="Lzma-14"></a>Lzma (14)</dt>
<dd>

<p>To write LZMA content, the module <code>IO::Uncompress::UnLzma</code> must be installed.</p>

</dd>
<dt id="Zstandard-(93)"><a class="permalink" href="./IO::Compress::Zip.html#Zstandard-(93)">#</a><a id="Zstandard"></a><a id="Zstandard-93"></a>Zstandard (93)</dt>
<dd>

<p>To write Zstandard content, the module <code>IO::Compress::Zstd</code> must be installed.</p>

</dd>
<dt id="Xz-(95)"><a class="permalink" href="./IO::Compress::Zip.html#Xz-(95)">#</a><a id="Xz"></a><a id="Xz-95"></a>Xz (95)</dt>
<dd>

<p>To write Xz content, the module <code>IO::Uncompress::UnXz</code> must be installed.</p>

</dd>
</dl>

<p>For reading zip files/buffers, see the companion module <a href="./IO::Uncompress::Unzip.html">IO::Uncompress::Unzip</a>.</p>

<h1 id="Functional-Interface"><a class="permalink" href="./IO::Compress::Zip.html#Functional-Interface">#</a><a id="Functional"></a>Functional Interface</h1>

<p>A top-level function, <code>zip</code>, is provided to carry out &quot;one-shot&quot; compression between buffers and/or files. For finer control over the compression process, see the <a href="./IO::Compress::Zip.html#OO-Interface">&quot;OO Interface&quot;</a> section.</p>

<pre><code>use IO::Compress::Zip qw(zip $ZipError) ;

zip $input_filename_or_reference =&gt; $output_filename_or_reference [,OPTS]
    or die &quot;zip failed: $ZipError\n&quot;;</code></pre>

<p>The functional interface needs Perl5.005 or better.</p>

<h2 id="zip-$input_filename_or_reference-=&gt;-$output_filename_or_reference-[,-OPTS]"><a class="permalink" href="./IO::Compress::Zip.html#zip-$input_filename_or_reference-=%3E-$output_filename_or_reference-%5B,-OPTS%5D">#</a><a id="zip"></a><a id="zip-input_filename_or_reference-output_filename_or_reference-OPTS"></a>zip $input_filename_or_reference =&gt; $output_filename_or_reference [, OPTS]</h2>

<p><code>zip</code> expects at least two parameters, <code>$input_filename_or_reference</code> and <code>$output_filename_or_reference</code> and zero or more optional parameters (see <a href="./IO::Compress::Zip.html#Optional-Parameters">&quot;Optional Parameters&quot;</a>)</p>

<h3 id="The-$input_filename_or_reference-parameter"><a class="permalink" href="./IO::Compress::Zip.html#The-$input_filename_or_reference-parameter">#</a><a id="The"></a><a id="The-input_filename_or_reference-parameter"></a>The <code>$input_filename_or_reference</code> parameter</h3>

<p>The parameter, <code>$input_filename_or_reference</code>, is used to define the source of the uncompressed data.</p>

<p>It can take one of the following forms:</p>

<dl>

<dt id="A-filename"><a class="permalink" href="./IO::Compress::Zip.html#A-filename">#</a><a id="A"></a>A filename</dt>
<dd>

<p>If the <code>$input_filename_or_reference</code> parameter is a simple scalar, it is assumed to be a filename. This file will be opened for reading and the input data will be read from it.</p>

</dd>
<dt id="A-filehandle"><a class="permalink" href="./IO::Compress::Zip.html#A-filehandle">#</a><a id="A1"></a>A filehandle</dt>
<dd>

<p>If the <code>$input_filename_or_reference</code> parameter is a filehandle, the input data will be read from it. The string &#39;-&#39; can be used as an alias for standard input.</p>

</dd>
<dt id="A-scalar-reference"><a class="permalink" href="./IO::Compress::Zip.html#A-scalar-reference">#</a><a id="A2"></a>A scalar reference</dt>
<dd>

<p>If <code>$input_filename_or_reference</code> is a scalar reference, the input data will be read from <code>$$input_filename_or_reference</code>.</p>

</dd>
<dt id="An-array-reference"><a class="permalink" href="./IO::Compress::Zip.html#An-array-reference">#</a><a id="An"></a>An array reference</dt>
<dd>

<p>If <code>$input_filename_or_reference</code> is an array reference, each element in the array must be a filename.</p>

<p>The input data will be read from each file in turn.</p>

<p>The complete array will be walked to ensure that it only contains valid filenames before any data is compressed.</p>

</dd>
<dt id="An-Input-FileGlob-string"><a class="permalink" href="./IO::Compress::Zip.html#An-Input-FileGlob-string">#</a><a id="An1"></a>An Input FileGlob string</dt>
<dd>

<p>If <code>$input_filename_or_reference</code> is a string that is delimited by the characters &quot;&lt;&quot; and &quot;&gt;&quot; <code>zip</code> will assume that it is an <i>input fileglob string</i>. The input is the list of files that match the fileglob.</p>

<p>See <a href="./File::GlobMapper.html">File::GlobMapper</a> for more details.</p>

</dd>
</dl>

<p>If the <code>$input_filename_or_reference</code> parameter is any other type, <code>undef</code> will be returned.</p>

<p>In addition, if <code>$input_filename_or_reference</code> is a simple filename, the default values for the <code>Name</code>, <code>Time</code>, <code>TextFlag</code>, <code>ExtAttr</code>, <code>exUnixN</code> and <code>exTime</code> options will be sourced from that file.</p>

<p>If you do not want to use these defaults they can be overridden by explicitly setting the <code>Name</code>, <code>Time</code>, <code>TextFlag</code>, <code>ExtAttr</code>, <code>exUnixN</code> and <code>exTime</code> options or by setting the <code>Minimal</code> parameter.</p>

<h3 id="The-$output_filename_or_reference-parameter"><a class="permalink" href="./IO::Compress::Zip.html#The-$output_filename_or_reference-parameter">#</a><a id="The1"></a><a id="The-output_filename_or_reference-parameter"></a>The <code>$output_filename_or_reference</code> parameter</h3>

<p>The parameter <code>$output_filename_or_reference</code> is used to control the destination of the compressed data. This parameter can take one of these forms.</p>

<dl>

<dt id="A-filename1"><a class="permalink" href="./IO::Compress::Zip.html#A-filename1">#</a><a id="A3"></a>A filename</dt>
<dd>

<p>If the <code>$output_filename_or_reference</code> parameter is a simple scalar, it is assumed to be a filename. This file will be opened for writing and the compressed data will be written to it.</p>

</dd>
<dt id="A-filehandle1"><a class="permalink" href="./IO::Compress::Zip.html#A-filehandle1">#</a><a id="A4"></a>A filehandle</dt>
<dd>

<p>If the <code>$output_filename_or_reference</code> parameter is a filehandle, the compressed data will be written to it. The string &#39;-&#39; can be used as an alias for standard output.</p>

</dd>
<dt id="A-scalar-reference1"><a class="permalink" href="./IO::Compress::Zip.html#A-scalar-reference1">#</a><a id="A5"></a>A scalar reference</dt>
<dd>

<p>If <code>$output_filename_or_reference</code> is a scalar reference, the compressed data will be stored in <code>$$output_filename_or_reference</code>.</p>

</dd>
<dt id="An-Array-Reference"><a class="permalink" href="./IO::Compress::Zip.html#An-Array-Reference">#</a><a id="An2"></a>An Array Reference</dt>
<dd>

<p>If <code>$output_filename_or_reference</code> is an array reference, the compressed data will be pushed onto the array.</p>

</dd>
<dt id="An-Output-FileGlob"><a class="permalink" href="./IO::Compress::Zip.html#An-Output-FileGlob">#</a><a id="An3"></a>An Output FileGlob</dt>
<dd>

<p>If <code>$output_filename_or_reference</code> is a string that is delimited by the characters &quot;&lt;&quot; and &quot;&gt;&quot; <code>zip</code> will assume that it is an <i>output fileglob string</i>. The output is the list of files that match the fileglob.</p>

<p>When <code>$output_filename_or_reference</code> is an fileglob string, <code>$input_filename_or_reference</code> must also be a fileglob string. Anything else is an error.</p>

<p>See <a href="./File::GlobMapper.html">File::GlobMapper</a> for more details.</p>

</dd>
</dl>

<p>If the <code>$output_filename_or_reference</code> parameter is any other type, <code>undef</code> will be returned.</p>

<h2 id="Notes"><a class="permalink" href="./IO::Compress::Zip.html#Notes">#</a>Notes</h2>

<p>When <code>$input_filename_or_reference</code> maps to multiple files/buffers and <code>$output_filename_or_reference</code> is a single file/buffer the input files/buffers will each be stored in <code>$output_filename_or_reference</code> as a distinct entry.</p>

<h2 id="Optional-Parameters"><a class="permalink" href="./IO::Compress::Zip.html#Optional-Parameters">#</a><a id="Optional"></a>Optional Parameters</h2>

<p>The optional parameters for the one-shot function <code>zip</code> are (for the most part) identical to those used with the OO interface defined in the <a href="./IO::Compress::Zip.html#Constructor-Options">&quot;Constructor Options&quot;</a> section. The exceptions are listed below</p>

<dl>

<dt id="AutoClose-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#AutoClose-=%3E-0%7C1">#</a><a id="AutoClose"></a><a id="AutoClose-0-1"></a><code>AutoClose =&gt; 0|1</code></dt>
<dd>

<p>This option applies to any input or output data streams to <code>zip</code> that are filehandles.</p>

<p>If <code>AutoClose</code> is specified, and the value is true, it will result in all input and/or output filehandles being closed once <code>zip</code> has completed.</p>

<p>This parameter defaults to 0.</p>

</dd>
<dt id="BinModeIn-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#BinModeIn-=%3E-0%7C1">#</a><a id="BinModeIn"></a><a id="BinModeIn-0-1"></a><code>BinModeIn =&gt; 0|1</code></dt>
<dd>

<p>This option is now a no-op. All files will be read in binmode.</p>

</dd>
<dt id="Append-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#Append-=%3E-0%7C1">#</a><a id="Append"></a><a id="Append-0-1"></a><code>Append =&gt; 0|1</code></dt>
<dd>

<p>The behaviour of this option is dependent on the type of output data stream.</p>

<ul>

<li><p>A Buffer</p>

<p>If <code>Append</code> is enabled, all compressed data will be append to the end of the output buffer. Otherwise the output buffer will be cleared before any compressed data is written to it.</p>

</li>
<li><p>A Filename</p>

<p>If <code>Append</code> is enabled, the file will be opened in append mode. Otherwise the contents of the file, if any, will be truncated before any compressed data is written to it.</p>

</li>
<li><p>A Filehandle</p>

<p>If <code>Append</code> is enabled, the filehandle will be positioned to the end of the file via a call to <code>seek</code> before any compressed data is written to it. Otherwise the file pointer will not be moved.</p>

</li>
</ul>

<p>When <code>Append</code> is specified, and set to true, it will <i>append</i> all compressed data to the output data stream.</p>

<p>So when the output is a filehandle it will carry out a seek to the eof before writing any compressed data. If the output is a filename, it will be opened for appending. If the output is a buffer, all compressed data will be appended to the existing buffer.</p>

<p>Conversely when <code>Append</code> is not specified, or it is present and is set to false, it will operate as follows.</p>

<p>When the output is a filename, it will truncate the contents of the file before writing any compressed data. If the output is a filehandle its position will not be changed. If the output is a buffer, it will be wiped before any compressed data is output.</p>

<p>Defaults to 0.</p>

</dd>
</dl>

<h2 id="Examples"><a class="permalink" href="./IO::Compress::Zip.html#Examples">#</a>Examples</h2>

<p>Here are a few example that show the capabilities of the module.</p>

<h3 id="Streaming"><a class="permalink" href="./IO::Compress::Zip.html#Streaming">#</a>Streaming</h3>

<p>This very simple command line example demonstrates the streaming capabilities of the module. The code reads data from STDIN, compresses it, and writes the compressed data to STDOUT.</p>

<pre><code class="plaintext">$ echo hello world | perl -MIO::Compress::Zip=zip -e &#39;zip \*STDIN =&gt; \*STDOUT&#39; &gt;output.zip</code></pre>

<p>The special filename &quot;-&quot; can be used as a standin for both <code>\*STDIN</code> and <code>\*STDOUT</code>, so the above can be rewritten as</p>

<pre><code class="plaintext">$ echo hello world | perl -MIO::Compress::Zip=zip -e &#39;zip &quot;-&quot; =&gt; &quot;-&quot;&#39; &gt;output.zip</code></pre>

<p>One problem with creating a zip archive directly from STDIN can be demonstrated by looking at the contents of the zip file, output.zip, that we have just created.</p>

<pre><code class="plaintext">$ unzip -l output.zip
Archive:  output.zip
Length      Date    Time    Name
---------  ---------- -----   ----
    12  2019-08-16 22:21
---------                     -------
    12                     1 file</code></pre>

<p>The archive member (filename) used is the empty string.</p>

<p>If that doesn&#39;t suit your needs, you can explicitly set the filename used in the zip archive by specifying the <a href="./IO::Compress::Zip.html#File-Naming-Options">Name</a> option, like so</p>

<pre><code class="plaintext">echo hello world | perl -MIO::Compress::Zip=zip -e &#39;zip &quot;-&quot; =&gt; &quot;-&quot;, Name =&gt; &quot;hello.txt&quot;&#39; &gt;output.zip</code></pre>

<p>Now the contents of the zip file looks like this</p>

<pre><code class="plaintext">$ unzip -l output.zip
Archive:  output.zip
Length      Date    Time    Name
---------  ---------- -----   ----
    12  2019-08-16 22:22   hello.txt
---------                     -------
    12                     1 file</code></pre>

<h3 id="Compressing-a-file-from-the-filesystem"><a class="permalink" href="./IO::Compress::Zip.html#Compressing-a-file-from-the-filesystem">#</a><a id="Compressing"></a>Compressing a file from the filesystem</h3>

<p>To read the contents of the file <code>file1.txt</code> and write the compressed data to the file <code>file1.txt.zip</code>.</p>

<pre><code>use strict ;
use warnings ;
use IO::Compress::Zip qw(zip $ZipError) ;

my $input = &quot;file1.txt&quot;;
zip $input =&gt; &quot;$input.zip&quot;
    or die &quot;zip failed: $ZipError\n&quot;;</code></pre>

<h3 id="Reading-from-a-Filehandle-and-writing-to-an-in-memory-buffer"><a class="permalink" href="./IO::Compress::Zip.html#Reading-from-a-Filehandle-and-writing-to-an-in-memory-buffer">#</a><a id="Reading"></a>Reading from a Filehandle and writing to an in-memory buffer</h3>

<p>To read from an existing Perl filehandle, <code>$input</code>, and write the compressed data to a buffer, <code>$buffer</code>.</p>

<pre><code>use strict ;
use warnings ;
use IO::Compress::Zip qw(zip $ZipError) ;
use IO::File ;

my $input = IO::File-&gt;new( &quot;&lt;file1.txt&quot; )
    or die &quot;Cannot open &#39;file1.txt&#39;: $!\n&quot; ;
my $buffer ;
zip $input =&gt; \$buffer
    or die &quot;zip failed: $ZipError\n&quot;;</code></pre>

<h3 id="Compressing-multiple-files"><a class="permalink" href="./IO::Compress::Zip.html#Compressing-multiple-files">#</a><a id="Compressing1"></a>Compressing multiple files</h3>

<p>To create a zip file, <code>output.zip</code>, that contains the compressed contents of the files <code>alpha.txt</code> and <code>beta.txt</code></p>

<pre><code>use strict ;
use warnings ;
use IO::Compress::Zip qw(zip $ZipError) ;

zip [ &#39;alpha.txt&#39;, &#39;beta.txt&#39; ] =&gt; &#39;output.zip&#39;
    or die &quot;zip failed: $ZipError\n&quot;;</code></pre>

<p>Alternatively, rather than having to explicitly name each of the files that you want to compress, you could use a fileglob to select all the <code>txt</code> files in the current directory, as follows</p>

<pre><code>use strict ;
use warnings ;
use IO::Compress::Zip qw(zip $ZipError) ;

my @files = &lt;*.txt&gt;;
zip \@files =&gt; &#39;output.zip&#39;
    or die &quot;zip failed: $ZipError\n&quot;;</code></pre>

<p>or more succinctly</p>

<pre><code>zip [ &lt;*.txt&gt; ] =&gt; &#39;output.zip&#39;
    or die &quot;zip failed: $ZipError\n&quot;;</code></pre>

<h1 id="OO-Interface"><a class="permalink" href="./IO::Compress::Zip.html#OO-Interface">#</a><a id="OO"></a>OO Interface</h1>

<h2 id="Constructor"><a class="permalink" href="./IO::Compress::Zip.html#Constructor">#</a>Constructor</h2>

<p>The format of the constructor for <code>IO::Compress::Zip</code> is shown below</p>

<pre><code>my $z = IO::Compress::Zip-&gt;new( $output [,OPTS] )
    or die &quot;IO::Compress::Zip failed: $ZipError\n&quot;;</code></pre>

<p>It returns an <code>IO::Compress::Zip</code> object on success and undef on failure. The variable <code>$ZipError</code> will contain an error message on failure.</p>

<p>If you are running Perl 5.005 or better the object, <code>$z</code>, returned from IO::Compress::Zip can be used exactly like an <a href="./IO::File.html">IO::File</a> filehandle. This means that all normal output file operations can be carried out with <code>$z</code>. For example, to write to a compressed file/buffer you can use either of these forms</p>

<pre><code>$z-&gt;print(&quot;hello world\n&quot;);
print $z &quot;hello world\n&quot;;</code></pre>

<p>The mandatory parameter <code>$output</code> is used to control the destination of the compressed data. This parameter can take one of these forms.</p>

<dl>

<dt id="A-filename2"><a class="permalink" href="./IO::Compress::Zip.html#A-filename2">#</a><a id="A6"></a>A filename</dt>
<dd>

<p>If the <code>$output</code> parameter is a simple scalar, it is assumed to be a filename. This file will be opened for writing and the compressed data will be written to it.</p>

</dd>
<dt id="A-filehandle2"><a class="permalink" href="./IO::Compress::Zip.html#A-filehandle2">#</a><a id="A7"></a>A filehandle</dt>
<dd>

<p>If the <code>$output</code> parameter is a filehandle, the compressed data will be written to it. The string &#39;-&#39; can be used as an alias for standard output.</p>

</dd>
<dt id="A-scalar-reference2"><a class="permalink" href="./IO::Compress::Zip.html#A-scalar-reference2">#</a><a id="A8"></a>A scalar reference</dt>
<dd>

<p>If <code>$output</code> is a scalar reference, the compressed data will be stored in <code>$$output</code>.</p>

</dd>
</dl>

<p>If the <code>$output</code> parameter is any other type, <code>IO::Compress::Zip</code>::new will return undef.</p>

<h2 id="Constructor-Options"><a class="permalink" href="./IO::Compress::Zip.html#Constructor-Options">#</a><a id="Constructor1"></a>Constructor Options</h2>

<p><code>OPTS</code> is any combination of zero or more the following options:</p>

<dl>

<dt id="AutoClose-=&gt;-0|11"><a class="permalink" href="./IO::Compress::Zip.html#AutoClose-=%3E-0%7C11">#</a><a id="AutoClose1"></a><a id="AutoClose-0-11"></a><code>AutoClose =&gt; 0|1</code></dt>
<dd>

<p>This option is only valid when the <code>$output</code> parameter is a filehandle. If specified, and the value is true, it will result in the <code>$output</code> being closed once either the <code>close</code> method is called or the <code>IO::Compress::Zip</code> object is destroyed.</p>

<p>This parameter defaults to 0.</p>

</dd>
<dt id="Append-=&gt;-0|11"><a class="permalink" href="./IO::Compress::Zip.html#Append-=%3E-0%7C11">#</a><a id="Append1"></a><a id="Append-0-11"></a><code>Append =&gt; 0|1</code></dt>
<dd>

<p>Opens <code>$output</code> in append mode.</p>

<p>The behaviour of this option is dependent on the type of <code>$output</code>.</p>

<ul>

<li><p>A Buffer</p>

<p>If <code>$output</code> is a buffer and <code>Append</code> is enabled, all compressed data will be append to the end of <code>$output</code>. Otherwise <code>$output</code> will be cleared before any data is written to it.</p>

</li>
<li><p>A Filename</p>

<p>If <code>$output</code> is a filename and <code>Append</code> is enabled, the file will be opened in append mode. Otherwise the contents of the file, if any, will be truncated before any compressed data is written to it.</p>

</li>
<li><p>A Filehandle</p>

<p>If <code>$output</code> is a filehandle, the file pointer will be positioned to the end of the file via a call to <code>seek</code> before any compressed data is written to it. Otherwise the file pointer will not be moved.</p>

</li>
</ul>

<p>This parameter defaults to 0.</p>

</dd>
</dl>

<h3 id="File-Naming-Options"><a class="permalink" href="./IO::Compress::Zip.html#File-Naming-Options">#</a><a id="File"></a>File Naming Options</h3>

<p>A quick bit of zip file terminology -- A zip archive consists of one or more <i>archive members</i>, where each member has an associated filename, known as the <i>archive member name</i>.</p>

<p>The options listed in this section control how the <i>archive member name</i> (or filename) is stored the zip archive.</p>

<dl>

<dt id="Name-=&gt;-$string"><a class="permalink" href="./IO::Compress::Zip.html#Name-=%3E-$string">#</a><a id="Name"></a><a id="Name-string"></a><code>Name =&gt; $string</code></dt>
<dd>

<p>This option is used to explicitly set the <i>archive member name</i> in the zip archive to <code>$string</code>. Most of the time you don&#39;t need to make use of this option. By default when adding a filename to the zip archive, the <i>archive member name</i> will match the filename.</p>

<p>You should only need to use this option if you want the <i>archive member name</i> to be different from the uncompressed filename or when the input is a filehandle or a buffer.</p>

<p>The default behaviour for what <i>archive member name</i> is used when the <code>Name</code> option is <i>not</i> specified depends on the form of the <code>$input</code> parameter:</p>

<ul>

<li><p>If the <code>$input</code> parameter is a filename, the value of <code>$input</code> will be used for the <i>archive member name</i> .</p>

</li>
<li><p>If the <code>$input</code> parameter is not a filename, the <i>archive member name</i> will be an empty string.</p>

</li>
</ul>

<p>Note that both the <code>CanonicalName</code> and <code>FilterName</code> options can modify the value used for the <i>archive member name</i>.</p>

<p>Also note that you should set the <code>Efs</code> option to true if you are working with UTF8 filenames.</p>

</dd>
<dt id="CanonicalName-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#CanonicalName-=%3E-0%7C1">#</a><a id="CanonicalName"></a><a id="CanonicalName-0-1"></a><code>CanonicalName =&gt; 0|1</code></dt>
<dd>

<p>This option controls whether the <i>archive member name</i> is <i>normalized</i> into Unix format before being written to the zip file.</p>

<p>It is recommended that you enable this option unless you really need to create a non-standard Zip file.</p>

<p>This is what APPNOTE.TXT has to say on what should be stored in the zip filename header field.</p>

<pre><code class="plaintext">The name of the file, with optional relative path.
The path stored should not contain a drive or
device letter, or a leading slash.  All slashes
should be forward slashes &#39;/&#39; as opposed to
backwards slashes &#39;\&#39; for compatibility with Amiga
and UNIX file systems etc.</code></pre>

<p>This option defaults to <b>false</b>.</p>

</dd>
<dt id="FilterName-=&gt;-sub-{-...-}"><a class="permalink" href="./IO::Compress::Zip.html#FilterName-=%3E-sub-%7B-...-%7D">#</a><a id="FilterName"></a><a id="FilterName-sub"></a><code>FilterName =&gt; sub { ... }</code></dt>
<dd>

<p>This option allow the <i>archive member</i> name to be modified before it is written to the zip file.</p>

<p>This option takes a parameter that must be a reference to a sub. On entry to the sub the <code>$_</code> variable will contain the name to be filtered. If no filename is available <code>$_</code> will contain an empty string.</p>

<p>The value of <code>$_</code> when the sub returns will be used as the <i>archive member name</i>.</p>

<p>Note that if <code>CanonicalName</code> is enabled, a normalized filename will be passed to the sub.</p>

<p>If you use <code>FilterName</code> to modify the filename, it is your responsibility to keep the filename in Unix format.</p>

<p>Although this option can be used with the OO interface, it is of most use with the one-shot interface. For example, the code below shows how <code>FilterName</code> can be used to remove the path component from a series of filenames before they are stored in <code>$zipfile</code>.</p>

<pre><code>sub compressTxtFiles
{
    my $zipfile = shift ;
    my $dir     = shift ;

    zip [ &lt;$dir/*.txt&gt; ] =&gt; $zipfile,
        FilterName =&gt; sub { s[^$dir/][] } ;
}</code></pre>

</dd>
<dt id="Efs-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#Efs-=%3E-0%7C1">#</a><a id="Efs"></a><a id="Efs-0-1"></a><code>Efs =&gt; 0|1</code></dt>
<dd>

<p>This option controls setting of the &quot;Language Encoding Flag&quot; (EFS) in the zip archive. When set, the filename and comment fields for the zip archive MUST be valid UTF-8.</p>

<p>If the string used for the filename and/or comment is not valid UTF-8 when this option is true, the script will die with a &quot;wide character&quot; error.</p>

<p>Note that this option only works with Perl 5.8.4 or better.</p>

<p>This option defaults to <b>false</b>.</p>

</dd>
</dl>

<h3 id="Overall-Zip-Archive-Structure"><a class="permalink" href="./IO::Compress::Zip.html#Overall-Zip-Archive-Structure">#</a><a id="Overall"></a>Overall Zip Archive Structure</h3>

<dl>

<dt id="Minimal-=&gt;-1|0"><a class="permalink" href="./IO::Compress::Zip.html#Minimal-=%3E-1%7C0">#</a><a id="Minimal"></a><a id="Minimal-1-0"></a><code>Minimal =&gt; 1|0</code></dt>
<dd>

<p>If specified, this option will disable the creation of all extra fields in the zip local and central headers. So the <code>exTime</code>, <code>exUnix2</code>, <code>exUnixN</code>, <code>ExtraFieldLocal</code> and <code>ExtraFieldCentral</code> options will be ignored.</p>

<p>This parameter defaults to 0.</p>

</dd>
<dt id="Stream-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#Stream-=%3E-0%7C1">#</a><a id="Stream"></a><a id="Stream-0-1"></a><code>Stream =&gt; 0|1</code></dt>
<dd>

<p>This option controls whether the zip file/buffer output is created in streaming mode.</p>

<p>Note that when outputting to a file with streaming mode disabled (<code>Stream</code> is 0), the output file must be seekable.</p>

<p>The default is 1.</p>

</dd>
<dt id="Zip64-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#Zip64-=%3E-0%7C1">#</a><a id="Zip64"></a><a id="Zip64-0-1"></a><code>Zip64 =&gt; 0|1</code></dt>
<dd>

<p>Create a Zip64 zip file/buffer. This option is used if you want to store files larger than 4 Gig or store more than 64K files in a single zip archive.</p>

<p><code>Zip64</code> will be automatically set, as needed, if working with the one-shot interface when the input is either a filename or a scalar reference.</p>

<p>If you intend to manipulate the Zip64 zip files created with this module using an external zip/unzip, make sure that it supports Zip64.</p>

<p>In particular, if you are using Info-Zip you need to have zip version 3.x or better to update a Zip64 archive and unzip version 6.x to read a zip64 archive.</p>

<p>The default is 0.</p>

</dd>
</dl>

<h3 id="Deflate-Compression-Options"><a class="permalink" href="./IO::Compress::Zip.html#Deflate-Compression-Options">#</a><a id="Deflate1"></a>Deflate Compression Options</h3>

<dl>

<dt id="-Level"><a class="permalink" href="./IO::Compress::Zip.html#-Level">#</a><a id="Level"></a>-Level</dt>
<dd>

<p>Defines the compression level used by zlib. The value should either be a number between 0 and 9 (0 means no compression and 9 is maximum compression), or one of the symbolic constants defined below.</p>

<pre><code class="plaintext">Z_NO_COMPRESSION
Z_BEST_SPEED
Z_BEST_COMPRESSION
Z_DEFAULT_COMPRESSION</code></pre>

<p>The default is Z_DEFAULT_COMPRESSION.</p>

<p>Note, these constants are not imported by <code>IO::Compress::Zip</code> by default.</p>

<pre><code>use IO::Compress::Zip qw(:strategy);
use IO::Compress::Zip qw(:constants);
use IO::Compress::Zip qw(:all);</code></pre>

</dd>
<dt id="-Strategy"><a class="permalink" href="./IO::Compress::Zip.html#-Strategy">#</a><a id="Strategy"></a>-Strategy</dt>
<dd>

<p>Defines the strategy used to tune the compression. Use one of the symbolic constants defined below.</p>

<pre><code class="plaintext">Z_FILTERED
Z_HUFFMAN_ONLY
Z_RLE
Z_FIXED
Z_DEFAULT_STRATEGY</code></pre>

<p>The default is Z_DEFAULT_STRATEGY.</p>

</dd>
</dl>

<h3 id="Bzip2-Compression-Options"><a class="permalink" href="./IO::Compress::Zip.html#Bzip2-Compression-Options">#</a><a id="Bzip21"></a>Bzip2 Compression Options</h3>

<dl>

<dt id="BlockSize100K-=&gt;-number"><a class="permalink" href="./IO::Compress::Zip.html#BlockSize100K-=%3E-number">#</a><a id="BlockSize100K"></a><a id="BlockSize100K-number"></a><code>BlockSize100K =&gt; number</code></dt>
<dd>

<p>Specify the number of 100K blocks bzip2 uses during compression.</p>

<p>Valid values are from 1 to 9, where 9 is best compression.</p>

<p>This option is only valid if the <code>Method</code> is ZIP_CM_BZIP2. It is ignored otherwise.</p>

<p>The default is 1.</p>

</dd>
<dt id="WorkFactor-=&gt;-number"><a class="permalink" href="./IO::Compress::Zip.html#WorkFactor-=%3E-number">#</a><a id="WorkFactor"></a><a id="WorkFactor-number"></a><code>WorkFactor =&gt; number</code></dt>
<dd>

<p>Specifies how much effort bzip2 should take before resorting to a slower fallback compression algorithm.</p>

<p>Valid values range from 0 to 250, where 0 means use the default value 30.</p>

<p>This option is only valid if the <code>Method</code> is ZIP_CM_BZIP2. It is ignored otherwise.</p>

<p>The default is 0.</p>

</dd>
</dl>

<h3 id="Lzma-and-Xz-Compression-Options"><a class="permalink" href="./IO::Compress::Zip.html#Lzma-and-Xz-Compression-Options">#</a><a id="Lzma1"></a>Lzma and Xz Compression Options</h3>

<dl>

<dt id="Preset-=&gt;-number"><a class="permalink" href="./IO::Compress::Zip.html#Preset-=%3E-number">#</a><a id="Preset"></a><a id="Preset-number"></a><code>Preset =&gt; number</code></dt>
<dd>

<p>Used to choose the LZMA compression preset.</p>

<p>Valid values are 0-9 and <code>LZMA_PRESET_DEFAULT</code>.</p>

<p>0 is the fastest compression with the lowest memory usage and the lowest compression.</p>

<p>9 is the slowest compression with the highest memory usage but with the best compression.</p>

<p>This option is only valid if the <code>Method</code> is ZIP_CM_LZMA. It is ignored otherwise.</p>

<p>Defaults to <code>LZMA_PRESET_DEFAULT</code> (6).</p>

</dd>
<dt id="Extreme-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#Extreme-=%3E-0%7C1">#</a><a id="Extreme"></a><a id="Extreme-0-1"></a><code>Extreme =&gt; 0|1</code></dt>
<dd>

<p>Makes LZMA compression a lot slower, but a small compression gain.</p>

<p>This option is only valid if the <code>Method</code> is ZIP_CM_LZMA. It is ignored otherwise.</p>

<p>Defaults to 0.</p>

</dd>
</dl>

<h3 id="Other-Options"><a class="permalink" href="./IO::Compress::Zip.html#Other-Options">#</a><a id="Other"></a>Other Options</h3>

<dl>

<dt id="Time-=&gt;-$number"><a class="permalink" href="./IO::Compress::Zip.html#Time-=%3E-$number">#</a><a id="Time"></a><a id="Time-number"></a><code>Time =&gt; $number</code></dt>
<dd>

<p>Sets the last modified time field in the zip header to $number.</p>

<p>This field defaults to the time the <code>IO::Compress::Zip</code> object was created if this option is not specified and the <code>$input</code> parameter is not a filename.</p>

</dd>
<dt id="ExtAttr-=&gt;-$attr"><a class="permalink" href="./IO::Compress::Zip.html#ExtAttr-=%3E-$attr">#</a><a id="ExtAttr"></a><a id="ExtAttr-attr"></a><code>ExtAttr =&gt; $attr</code></dt>
<dd>

<p>This option controls the &quot;external file attributes&quot; field in the central header of the zip file. This is a 4 byte field.</p>

<p>If you are running a Unix derivative this value defaults to</p>

<pre><code class="plaintext">0100644 &lt;&lt; 16</code></pre>

<p>This should allow read/write access to any files that are extracted from the zip file/buffer`.</p>

<p>For all other systems it defaults to 0.</p>

</dd>
<dt id="exTime-=&gt;-[$atime,-$mtime,-$ctime]"><a class="permalink" href="./IO::Compress::Zip.html#exTime-=%3E-%5B$atime,-$mtime,-$ctime%5D">#</a><a id="exTime"></a><a id="exTime-atime-mtime-ctime"></a><code>exTime =&gt; [$atime, $mtime, $ctime]</code></dt>
<dd>

<p>This option expects an array reference with exactly three elements: <code>$atime</code>, <code>mtime</code> and <code>$ctime</code>. These correspond to the last access time, last modification time and creation time respectively.</p>

<p>It uses these values to set the extended timestamp field (ID is &quot;UT&quot;) in the local zip header using the three values, $atime, $mtime, $ctime. In addition it sets the extended timestamp field in the central zip header using <code>$mtime</code>.</p>

<p>If any of the three values is <code>undef</code> that time value will not be used. So, for example, to set only the <code>$mtime</code> you would use this</p>

<pre><code>exTime =&gt; [undef, $mtime, undef]</code></pre>

<p>If the <code>Minimal</code> option is set to true, this option will be ignored.</p>

<p>By default no extended time field is created.</p>

</dd>
<dt id="exUnix2-=&gt;-[$uid,-$gid]"><a class="permalink" href="./IO::Compress::Zip.html#exUnix2-=%3E-%5B$uid,-$gid%5D">#</a><a id="exUnix2"></a><a id="exUnix2-uid-gid"></a><code>exUnix2 =&gt; [$uid, $gid]</code></dt>
<dd>

<p>This option expects an array reference with exactly two elements: <code>$uid</code> and <code>$gid</code>. These values correspond to the numeric User ID (UID) and Group ID (GID) of the owner of the files respectively.</p>

<p>When the <code>exUnix2</code> option is present it will trigger the creation of a Unix2 extra field (ID is &quot;Ux&quot;) in the local zip header. This will be populated with <code>$uid</code> and <code>$gid</code>. An empty Unix2 extra field will also be created in the central zip header.</p>

<p>Note - The UID &amp; GID are stored as 16-bit integers in the &quot;Ux&quot; field. Use <code>exUnixN</code> if your UID or GID are 32-bit.</p>

<p>If the <code>Minimal</code> option is set to true, this option will be ignored.</p>

<p>By default no Unix2 extra field is created.</p>

</dd>
<dt id="exUnixN-=&gt;-[$uid,-$gid]"><a class="permalink" href="./IO::Compress::Zip.html#exUnixN-=%3E-%5B$uid,-$gid%5D">#</a><a id="exUnixN"></a><a id="exUnixN-uid-gid"></a><code>exUnixN =&gt; [$uid, $gid]</code></dt>
<dd>

<p>This option expects an array reference with exactly two elements: <code>$uid</code> and <code>$gid</code>. These values correspond to the numeric User ID (UID) and Group ID (GID) of the owner of the files respectively.</p>

<p>When the <code>exUnixN</code> option is present it will trigger the creation of a UnixN extra field (ID is &quot;ux&quot;) in both the local and central zip headers. This will be populated with <code>$uid</code> and <code>$gid</code>. The UID &amp; GID are stored as 32-bit integers.</p>

<p>If the <code>Minimal</code> option is set to true, this option will be ignored.</p>

<p>By default no UnixN extra field is created.</p>

</dd>
<dt id="Comment-=&gt;-$comment"><a class="permalink" href="./IO::Compress::Zip.html#Comment-=%3E-$comment">#</a><a id="Comment"></a><a id="Comment-comment"></a><code>Comment =&gt; $comment</code></dt>
<dd>

<p>Stores the contents of <code>$comment</code> in the Central File Header of the zip file.</p>

<p>Set the <code>Efs</code> option to true if you want to store a UTF8 comment.</p>

<p>By default, no comment field is written to the zip file.</p>

</dd>
<dt id="ZipComment-=&gt;-$comment"><a class="permalink" href="./IO::Compress::Zip.html#ZipComment-=%3E-$comment">#</a><a id="ZipComment"></a><a id="ZipComment-comment"></a><code>ZipComment =&gt; $comment</code></dt>
<dd>

<p>Stores the contents of <code>$comment</code> in the End of Central Directory record of the zip file.</p>

<p>By default, no comment field is written to the zip file.</p>

</dd>
<dt id="Method-=&gt;-$method"><a class="permalink" href="./IO::Compress::Zip.html#Method-=%3E-$method">#</a><a id="Method"></a><a id="Method-method"></a><code>Method =&gt; $method</code></dt>
<dd>

<p>Controls which compression method is used. At present the compression methods supported are: Store (no compression at all), Deflate, Bzip2, Zstd, Xz and Lzma.</p>

<p>The symbols ZIP_CM_STORE, ZIP_CM_DEFLATE, ZIP_CM_BZIP2, ZIP_CM_ZSTD, ZIP_CM_XZ and ZIP_CM_LZMA are used to select the compression method.</p>

<p>These constants are not imported by <code>IO::Compress::Zip</code> by default.</p>

<pre><code>use IO::Compress::Zip qw(:zip_method);
use IO::Compress::Zip qw(:constants);
use IO::Compress::Zip qw(:all);</code></pre>

<p>Note that to create Bzip2 content, the module <code>IO::Compress::Bzip2</code> must be installed. A fatal error will be thrown if you attempt to create Bzip2 content when <code>IO::Compress::Bzip2</code> is not available.</p>

<p>Note that to create Lzma content, the module <code>IO::Compress::Lzma</code> must be installed. A fatal error will be thrown if you attempt to create Lzma content when <code>IO::Compress::Lzma</code> is not available.</p>

<p>Note that to create Xz content, the module <code>IO::Compress::Xz</code> must be installed. A fatal error will be thrown if you attempt to create Xz content when <code>IO::Compress::Xz</code> is not available.</p>

<p>Note that to create Zstd content, the module <code>IO::Compress::Zstd</code> must be installed. A fatal error will be thrown if you attempt to create Zstd content when <code>IO::Compress::Zstd</code> is not available.</p>

<p>The default method is ZIP_CM_DEFLATE.</p>

</dd>
<dt id="TextFlag-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#TextFlag-=%3E-0%7C1">#</a><a id="TextFlag"></a><a id="TextFlag-0-1"></a><code>TextFlag =&gt; 0|1</code></dt>
<dd>

<p>This parameter controls the setting of a bit in the zip central header. It is used to signal that the data stored in the zip file/buffer is probably text.</p>

<p>In one-shot mode this flag will be set to true if the Perl <code>-T</code> operator thinks the file contains text.</p>

<p>The default is 0.</p>

</dd>
<dt id="ExtraFieldLocal-=&gt;-$data"><a class="permalink" href="./IO::Compress::Zip.html#ExtraFieldLocal-=%3E-$data">#</a><a id="ExtraFieldLocal"></a><a id="ExtraFieldLocal-data"></a><code>ExtraFieldLocal =&gt; $data</code></dt>
<dd>

</dd>
<dt id="ExtraFieldCentral-=&gt;-$data"><a class="permalink" href="./IO::Compress::Zip.html#ExtraFieldCentral-=%3E-$data">#</a><a id="ExtraFieldCentral"></a><a id="ExtraFieldCentral-data"></a><code>ExtraFieldCentral =&gt; $data</code></dt>
<dd>

<p>The <code>ExtraFieldLocal</code> option is used to store additional metadata in the local header for the zip file/buffer. The <code>ExtraFieldCentral</code> does the same for the matching central header.</p>

<p>An extra field consists of zero or more subfields. Each subfield consists of a two byte header followed by the subfield data.</p>

<p>The list of subfields can be supplied in any of the following formats</p>

<pre><code>ExtraFieldLocal =&gt; [$id1, $data1,
                    $id2, $data2,
                     ...
                   ]

ExtraFieldLocal =&gt; [ [$id1 =&gt; $data1],
                     [$id2 =&gt; $data2],
                     ...
                   ]

ExtraFieldLocal =&gt; { $id1 =&gt; $data1,
                     $id2 =&gt; $data2,
                     ...
                   }</code></pre>

<p>Where <code>$id1</code>, <code>$id2</code> are two byte subfield ID&#39;s.</p>

<p>If you use the hash syntax, you have no control over the order in which the ExtraSubFields are stored, plus you cannot have SubFields with duplicate ID.</p>

<p>Alternatively the list of subfields can by supplied as a scalar, thus</p>

<pre><code>ExtraField =&gt; $rawdata</code></pre>

<p>In this case <code>IO::Compress::Zip</code> will check that <code>$rawdata</code> consists of zero or more conformant sub-fields.</p>

<p>The Extended Time field (ID &quot;UT&quot;), set using the <code>exTime</code> option, and the Unix2 extra field (ID &quot;Ux), set using the <code>exUnix2</code> option, are examples of extra fields.</p>

<p>If the <code>Minimal</code> option is set to true, this option will be ignored.</p>

<p>The maximum size of an extra field 65535 bytes.</p>

</dd>
<dt id="Strict-=&gt;-0|1"><a class="permalink" href="./IO::Compress::Zip.html#Strict-=%3E-0%7C1">#</a><a id="Strict"></a><a id="Strict-0-1"></a><code>Strict =&gt; 0|1</code></dt>
<dd>

<p>This is a placeholder option.</p>

</dd>
</dl>

<h2 id="Examples1"><a class="permalink" href="./IO::Compress::Zip.html#Examples1">#</a>Examples</h2>

<p>TODO</p>

<h1 id="Methods"><a class="permalink" href="./IO::Compress::Zip.html#Methods">#</a>Methods</h1>

<h2 id="print"><a class="permalink" href="./IO::Compress::Zip.html#print">#</a>print</h2>

<p>Usage is</p>

<pre><code>$z-&gt;print($data)
print $z $data</code></pre>

<p>Compresses and outputs the contents of the <code>$data</code> parameter. This has the same behaviour as the <code>print</code> built-in.</p>

<p>Returns true if successful.</p>

<h2 id="printf"><a class="permalink" href="./IO::Compress::Zip.html#printf">#</a>printf</h2>

<p>Usage is</p>

<pre><code>$z-&gt;printf($format, $data)
printf $z $format, $data</code></pre>

<p>Compresses and outputs the contents of the <code>$data</code> parameter.</p>

<p>Returns true if successful.</p>

<h2 id="syswrite"><a class="permalink" href="./IO::Compress::Zip.html#syswrite">#</a>syswrite</h2>

<p>Usage is</p>

<pre><code>$z-&gt;syswrite $data
$z-&gt;syswrite $data, $length
$z-&gt;syswrite $data, $length, $offset</code></pre>

<p>Compresses and outputs the contents of the <code>$data</code> parameter.</p>

<p>Returns the number of uncompressed bytes written, or <code>undef</code> if unsuccessful.</p>

<h2 id="write"><a class="permalink" href="./IO::Compress::Zip.html#write">#</a>write</h2>

<p>Usage is</p>

<pre><code>$z-&gt;write $data
$z-&gt;write $data, $length
$z-&gt;write $data, $length, $offset</code></pre>

<p>Compresses and outputs the contents of the <code>$data</code> parameter.</p>

<p>Returns the number of uncompressed bytes written, or <code>undef</code> if unsuccessful.</p>

<h2 id="flush"><a class="permalink" href="./IO::Compress::Zip.html#flush">#</a>flush</h2>

<p>Usage is</p>

<pre><code>$z-&gt;flush;
$z-&gt;flush($flush_type);</code></pre>

<p>Flushes any pending compressed data to the output file/buffer.</p>

<p>This method takes an optional parameter, <code>$flush_type</code>, that controls how the flushing will be carried out. By default the <code>$flush_type</code> used is <code>Z_FINISH</code>. Other valid values for <code>$flush_type</code> are <code>Z_NO_FLUSH</code>, <code>Z_SYNC_FLUSH</code>, <code>Z_FULL_FLUSH</code> and <code>Z_BLOCK</code>. It is strongly recommended that you only set the <code>flush_type</code> parameter if you fully understand the implications of what it does - overuse of <code>flush</code> can seriously degrade the level of compression achieved. See the <code>zlib</code> documentation for details.</p>

<p>Returns true on success.</p>

<h2 id="tell"><a class="permalink" href="./IO::Compress::Zip.html#tell">#</a>tell</h2>

<p>Usage is</p>

<pre><code>$z-&gt;tell()
tell $z</code></pre>

<p>Returns the uncompressed file offset.</p>

<h2 id="eof"><a class="permalink" href="./IO::Compress::Zip.html#eof">#</a>eof</h2>

<p>Usage is</p>

<pre><code>$z-&gt;eof();
eof($z);</code></pre>

<p>Returns true if the <code>close</code> method has been called.</p>

<h2 id="seek"><a class="permalink" href="./IO::Compress::Zip.html#seek">#</a>seek</h2>

<pre><code>$z-&gt;seek($position, $whence);
seek($z, $position, $whence);</code></pre>

<p>Provides a sub-set of the <code>seek</code> functionality, with the restriction that it is only legal to seek forward in the output file/buffer. It is a fatal error to attempt to seek backward.</p>

<p>Empty parts of the file/buffer will have NULL (0x00) bytes written to them.</p>

<p>The <code>$whence</code> parameter takes one the usual values, namely SEEK_SET, SEEK_CUR or SEEK_END.</p>

<p>Returns 1 on success, 0 on failure.</p>

<h2 id="binmode"><a class="permalink" href="./IO::Compress::Zip.html#binmode">#</a>binmode</h2>

<p>Usage is</p>

<pre><code>$z-&gt;binmode
binmode $z ;</code></pre>

<p>This is a noop provided for completeness.</p>

<h2 id="opened"><a class="permalink" href="./IO::Compress::Zip.html#opened">#</a>opened</h2>

<pre><code>$z-&gt;opened()</code></pre>

<p>Returns true if the object currently refers to a opened file/buffer.</p>

<h2 id="autoflush"><a class="permalink" href="./IO::Compress::Zip.html#autoflush">#</a>autoflush</h2>

<pre><code>my $prev = $z-&gt;autoflush()
my $prev = $z-&gt;autoflush(EXPR)</code></pre>

<p>If the <code>$z</code> object is associated with a file or a filehandle, this method returns the current autoflush setting for the underlying filehandle. If <code>EXPR</code> is present, and is non-zero, it will enable flushing after every write/print operation.</p>

<p>If <code>$z</code> is associated with a buffer, this method has no effect and always returns <code>undef</code>.</p>

<p><b>Note</b> that the special variable <code>$|</code> <b>cannot</b> be used to set or retrieve the autoflush setting.</p>

<h2 id="input_line_number"><a class="permalink" href="./IO::Compress::Zip.html#input_line_number">#</a>input_line_number</h2>

<pre><code>$z-&gt;input_line_number()
$z-&gt;input_line_number(EXPR)</code></pre>

<p>This method always returns <code>undef</code> when compressing.</p>

<h2 id="fileno"><a class="permalink" href="./IO::Compress::Zip.html#fileno">#</a>fileno</h2>

<pre><code>$z-&gt;fileno()
fileno($z)</code></pre>

<p>If the <code>$z</code> object is associated with a file or a filehandle, <code>fileno</code> will return the underlying file descriptor. Once the <code>close</code> method is called <code>fileno</code> will return <code>undef</code>.</p>

<p>If the <code>$z</code> object is associated with a buffer, this method will return <code>undef</code>.</p>

<h2 id="close"><a class="permalink" href="./IO::Compress::Zip.html#close">#</a>close</h2>

<pre><code>$z-&gt;close() ;
close $z ;</code></pre>

<p>Flushes any pending compressed data and then closes the output file/buffer.</p>

<p>For most versions of Perl this method will be automatically invoked if the IO::Compress::Zip object is destroyed (either explicitly or by the variable with the reference to the object going out of scope). The exceptions are Perl versions 5.005 through 5.00504 and 5.8.0. In these cases, the <code>close</code> method will be called automatically, but not until global destruction of all live objects when the program is terminating.</p>

<p>Therefore, if you want your scripts to be able to run on all versions of Perl, you should call <code>close</code> explicitly and not rely on automatic closing.</p>

<p>Returns true on success, otherwise 0.</p>

<p>If the <code>AutoClose</code> option has been enabled when the IO::Compress::Zip object was created, and the object is associated with a file, the underlying file will also be closed.</p>

<h2 id="newStream([OPTS])"><a class="permalink" href="./IO::Compress::Zip.html#newStream(%5BOPTS%5D)">#</a><a id="newStream"></a><a id="newStream-OPTS"></a>newStream([OPTS])</h2>

<p>Usage is</p>

<pre><code>$z-&gt;newStream( [OPTS] )</code></pre>

<p>Closes the current compressed data stream and starts a new one.</p>

<p>OPTS consists of any of the options that are available when creating the <code>$z</code> object.</p>

<p>See the <a href="./IO::Compress::Zip.html#Constructor-Options">&quot;Constructor Options&quot;</a> section for more details.</p>

<h2 id="deflateParams"><a class="permalink" href="./IO::Compress::Zip.html#deflateParams">#</a>deflateParams</h2>

<p>Usage is</p>

<pre><code>$z-&gt;deflateParams</code></pre>

<p>TODO</p>

<h1 id="Importing"><a class="permalink" href="./IO::Compress::Zip.html#Importing">#</a>Importing</h1>

<p>A number of symbolic constants are required by some methods in <code>IO::Compress::Zip</code>. None are imported by default.</p>

<dl>

<dt id=":all"><a class="permalink" href="./IO::Compress::Zip.html#:all">#</a><a id="all"></a>:all</dt>
<dd>

<p>Imports <code>zip</code>, <code>$ZipError</code> and all symbolic constants that can be used by <code>IO::Compress::Zip</code>. Same as doing this</p>

<pre><code>use IO::Compress::Zip qw(zip $ZipError :constants) ;</code></pre>

</dd>
<dt id=":constants"><a class="permalink" href="./IO::Compress::Zip.html#:constants">#</a><a id="constants"></a>:constants</dt>
<dd>

<p>Import all symbolic constants. Same as doing this</p>

<pre><code>use IO::Compress::Zip qw(:flush :level :strategy :zip_method) ;</code></pre>

</dd>
<dt id=":flush"><a class="permalink" href="./IO::Compress::Zip.html#:flush">#</a><a id="flush1"></a>:flush</dt>
<dd>

<p>These symbolic constants are used by the <code>flush</code> method.</p>

<pre><code class="plaintext">Z_NO_FLUSH
Z_PARTIAL_FLUSH
Z_SYNC_FLUSH
Z_FULL_FLUSH
Z_FINISH
Z_BLOCK</code></pre>

</dd>
<dt id=":level"><a class="permalink" href="./IO::Compress::Zip.html#:level">#</a><a id="level"></a>:level</dt>
<dd>

<p>These symbolic constants are used by the <code>Level</code> option in the constructor.</p>

<pre><code class="plaintext">Z_NO_COMPRESSION
Z_BEST_SPEED
Z_BEST_COMPRESSION
Z_DEFAULT_COMPRESSION</code></pre>

</dd>
<dt id=":strategy"><a class="permalink" href="./IO::Compress::Zip.html#:strategy">#</a><a id="strategy"></a>:strategy</dt>
<dd>

<p>These symbolic constants are used by the <code>Strategy</code> option in the constructor.</p>

<pre><code class="plaintext">Z_FILTERED
Z_HUFFMAN_ONLY
Z_RLE
Z_FIXED
Z_DEFAULT_STRATEGY</code></pre>

</dd>
<dt id=":zip_method"><a class="permalink" href="./IO::Compress::Zip.html#:zip_method">#</a><a id="zip_method"></a>:zip_method</dt>
<dd>

<p>These symbolic constants are used by the <code>Method</code> option in the constructor.</p>

<pre><code class="plaintext">ZIP_CM_STORE
ZIP_CM_DEFLATE
ZIP_CM_BZIP2</code></pre>

</dd>
</dl>

<h1 id="EXAMPLES"><a class="permalink" href="./IO::Compress::Zip.html#EXAMPLES">#</a>EXAMPLES</h1>

<h2 id="Apache::GZip-Revisited"><a class="permalink" href="./IO::Compress::Zip.html#Apache::GZip-Revisited">#</a><a id="Apache"></a>Apache::GZip Revisited</h2>

<p>See <a href="./IO::Compress::FAQ.html#Apache%3A%3AGZip-Revisited">IO::Compress::FAQ</a></p>

<h2 id="Working-with-Net::FTP"><a class="permalink" href="./IO::Compress::Zip.html#Working-with-Net::FTP">#</a><a id="Working"></a>Working with Net::FTP</h2>

<p>See <a href="./IO::Compress::FAQ.html#Compressed-files-and-Net%3A%3AFTP">IO::Compress::FAQ</a></p>

<h1 id="SUPPORT"><a class="permalink" href="./IO::Compress::Zip.html#SUPPORT">#</a>SUPPORT</h1>

<p>General feedback/questions/bug reports should be sent to <a href="https://github.com/pmqs/IO-Compress/issues">https://github.com/pmqs/IO-Compress/issues</a> (preferred) or <a href="https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress">https://rt.cpan.org/Public/Dist/Display.html?Name=IO-Compress</a>.</p>

<h1 id="SEE-ALSO"><a class="permalink" href="./IO::Compress::Zip.html#SEE-ALSO">#</a><a id="SEE"></a>SEE ALSO</h1>

<p><a href="./Compress::Zlib.html">Compress::Zlib</a>, <a href="./IO::Compress::Gzip.html">IO::Compress::Gzip</a>, <a href="./IO::Uncompress::Gunzip.html">IO::Uncompress::Gunzip</a>, <a href="./IO::Compress::Deflate.html">IO::Compress::Deflate</a>, <a href="./IO::Uncompress::Inflate.html">IO::Uncompress::Inflate</a>, <a href="./IO::Compress::RawDeflate.html">IO::Compress::RawDeflate</a>, <a href="./IO::Uncompress::RawInflate.html">IO::Uncompress::RawInflate</a>, <a href="./IO::Compress::Bzip2.html">IO::Compress::Bzip2</a>, <a href="./IO::Uncompress::Bunzip2.html">IO::Uncompress::Bunzip2</a>, <a href="./IO::Compress::Lzma.html">IO::Compress::Lzma</a>, <a href="./IO::Uncompress::UnLzma.html">IO::Uncompress::UnLzma</a>, <a href="./IO::Compress::Xz.html">IO::Compress::Xz</a>, <a href="./IO::Uncompress::UnXz.html">IO::Uncompress::UnXz</a>, <a href="./IO::Compress::Lzip.html">IO::Compress::Lzip</a>, <a href="./IO::Uncompress::UnLzip.html">IO::Uncompress::UnLzip</a>, <a href="./IO::Compress::Lzop.html">IO::Compress::Lzop</a>, <a href="./IO::Uncompress::UnLzop.html">IO::Uncompress::UnLzop</a>, <a href="./IO::Compress::Lzf.html">IO::Compress::Lzf</a>, <a href="./IO::Uncompress::UnLzf.html">IO::Uncompress::UnLzf</a>, <a href="./IO::Compress::Zstd.html">IO::Compress::Zstd</a>, <a href="./IO::Uncompress::UnZstd.html">IO::Uncompress::UnZstd</a>, <a href="./IO::Uncompress::AnyInflate.html">IO::Uncompress::AnyInflate</a>, <a href="./IO::Uncompress::AnyUncompress.html">IO::Uncompress::AnyUncompress</a></p>

<p><a href="./IO::Compress::FAQ.html">IO::Compress::FAQ</a></p>

<p><a href="./File::GlobMapper.html">File::GlobMapper</a>, <a href="./Archive::Zip.html">Archive::Zip</a>, <a href="./Archive::Tar.html">Archive::Tar</a>, <a href="./IO::Zlib.html">IO::Zlib</a></p>

<p>For RFC 1950, 1951 and 1952 see <a href="http://www.faqs.org/rfcs/rfc1950.html">http://www.faqs.org/rfcs/rfc1950.html</a>, <a href="http://www.faqs.org/rfcs/rfc1951.html">http://www.faqs.org/rfcs/rfc1951.html</a> and <a href="http://www.faqs.org/rfcs/rfc1952.html">http://www.faqs.org/rfcs/rfc1952.html</a></p>

<p>The <i>zlib</i> compression library was written by Jean-loup Gailly <code>gzip@prep.ai.mit.edu</code> and Mark Adler <code>madler@alumni.caltech.edu</code>.</p>

<p>The primary site for the <i>zlib</i> compression library is <a href="http://www.zlib.org">http://www.zlib.org</a>.</p>

<p>The primary site for gzip is <a href="http://www.gzip.org">http://www.gzip.org</a>.</p>

<h1 id="AUTHOR"><a class="permalink" href="./IO::Compress::Zip.html#AUTHOR">#</a>AUTHOR</h1>

<p>This module was written by Paul Marquess, <code>pmqs@cpan.org</code>.</p>

<h1 id="MODIFICATION-HISTORY"><a class="permalink" href="./IO::Compress::Zip.html#MODIFICATION-HISTORY">#</a><a id="MODIFICATION"></a>MODIFICATION HISTORY</h1>

<p>See the Changes file.</p>

<h1 id="COPYRIGHT-AND-LICENSE"><a class="permalink" href="./IO::Compress::Zip.html#COPYRIGHT-AND-LICENSE">#</a><a id="COPYRIGHT"></a>COPYRIGHT AND LICENSE</h1>

<p>Copyright (c) 2005-2021 Paul Marquess. All rights reserved.</p>

<p>This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.</p>


      </div>
      <div id="footer">
        <p>Perldoc Browser is maintained by Dan Book (<a href="https://metacpan.org/author/DBOOK">DBOOK</a>). Please contact him via the <a href="https://github.com/Grinnz/perldoc-browser/issues">GitHub issue tracker</a> or <a href="mailto:dbook@cpan.org">email</a> regarding any issues with the site itself, search, or rendering of documentation.</p>

<p>The Perl documentation is maintained by the Perl 5 Porters in the development of Perl. Please contact them via the <a href="https://github.com/Perl/perl5/issues">Perl issue tracker</a>, the <a href="https://lists.perl.org/list/perl5-porters.html">mailing list</a>, or <a href="https://kiwiirc.com/client/irc.perl.org/p5p">IRC</a> to report any issues with the contents or format of the documentation.</p>


      </div>
    </div>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.5.1/jquery.slim.min.js" integrity="sha512-/DXTXr6nQodMUiq+IUJYCt2PPOUjrHJ9wFrqpJ3XkgPNOZVfMok7cRw6CSxyCQxXn6ozlESsSh1/sMCTF1rL/g==" crossorigin="anonymous"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.1/umd/popper.min.js" integrity="sha512-ubuT8Z88WxezgSqf3RLuNi5lmjstiJcyezx34yIU2gAHonIi27Na7atqzUZCOoY4CExaoFumzOsFQ2Ch+I/HCw==" crossorigin="anonymous"></script>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
    <script src="../highlight.pack.js"></script>
    <script>hljs.highlightAll();</script>
  </body>
</html>
